package com.dianzhihan.cashier.model.product;

import com.dianzhihan.cashier.mapper.ProductMapper;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

/**
 * @author Dianzhi Han
 * @version 1.0
 * @description: 这个对象只是承载请求参数的，要求属性的名称必须和 form 表单中的 input 的 name 一致
 * @date 2023/2/7 2:31
 */

@Data
@Slf4j

//都是String类型的属性
public class ProductParam {
    private String productId;
    private String productname;
    private String description;
    private String stock;
    private String unit;
    private String price;
    private String discount;

    public void validate(String module, String redirectUrl) {
        NameValidator nameValidator = new NameValidator();
        nameValidator.validate(productname,module,redirectUrl);
        DescriptionValidator descriptionValidator = new DescriptionValidator();
        descriptionValidator.validate(description,module,redirectUrl);
        PriceValidator priceValidator = new PriceValidator();
        priceValidator.validate(price,module,redirectUrl);
        StockValidator stockValidator = new StockValidator();
        stockValidator.validate(stock,module,redirectUrl);
        UnitValidator unitValidator = new UnitValidator();
        unitValidator.validate(unit,module,redirectUrl);
        DiscountValidator discountValidator = new DiscountValidator();
        discountValidator.validate(discount,module,redirectUrl);
    }

    public void validate(String module, String redirectUrl, ProductMapper productMapper) {
        ProductIDValidator productIDValidator = new ProductIDValidator();
        productIDValidator.validate(productId,module,redirectUrl,productMapper);
        NameValidator nameValidator = new NameValidator();
        nameValidator.validate(productname,module,redirectUrl);
        DescriptionValidator descriptionValidator = new DescriptionValidator();
        descriptionValidator.validate(description,module,redirectUrl);
        PriceValidator priceValidator = new PriceValidator();
        priceValidator.validate(price,module,redirectUrl);
        StockValidator stockValidator = new StockValidator();
        stockValidator.validate(stock,module,redirectUrl);
        UnitValidator unitValidator = new UnitValidator();
        unitValidator.validate(unit,module,redirectUrl);
        DiscountValidator discountValidator = new DiscountValidator();
        discountValidator.validate(discount,module,redirectUrl);
    }
}
